#!/bin/bash

# This script will upload the given local images to a registry server ($registry is the default value).
# Usage:  push_images image1 [image2...]
# Author: Mongo
# Create: 2014-05-26
# Change Author happykala
# Change Log 更新docker私有仓库的容器地址
# File Use description 当前这个文件最好放在linux的可执行文件目录下，这里已ubuntu为例
# 路径是'/usr/local/bin',然后为本文件添加可执行的权限chmod a+x /usr/local/bin/pull.sh
# 这样之后就可以使用这个文件批量拉取指定的镜像数据了
#The registry server address where you want push the images into
registry=112.74.178.191:5000

### DO NOT MODIFY THE FOLLOWING PART, UNLESS YOU KNOW WHAT IT MEANS ###
echo_g () {
    [ $# -ne 1 ] && return 0
    echo -e "\033[32m$1\033[0m"
}

echo_b () {
    [ $# -ne 1 ] && return 0
    echo -e "\033[34m$1\033[0m"
}

usage() {
    sudo docker images
    echo "Usage: $0 registry1:tag1 [registry2:tag2...]"
}

[ $# -lt 1 ] && usage && exit

echo_b "The registry server is $registry"

for image in "$@"
    do
        echo_b "Downloading $image..."
        sudo docker pull $registry/$image
        sudo docker tag $registry/$image $image
        sudo docker rmi $registry/$image
        echo_g "Download $image Success!"
    done